//JavaScript Framework 2.0 Code
try{
Type.registerNamespace('com.yonyou.ncmm_pac_pda.StockUpScanController');
com.yonyou.ncmm_pac_pda.StockUpScanController = function() {
    com.yonyou.ncmm_pac_pda.StockUpScanController.initializeBase(this);
    this.initialize();
}
function com$yonyou$ncmm_pac_pda$StockUpScanController$initialize(){
    //you can programing by $ctx API
    //get the context data through $ctx.get()
    //set the context data through $ctx.push(json)
    //set the field of the context through $ctx.put(fieldName, fieldValue)
    //get the parameter of the context through $ctx.param(parameterName)
    //Demo Code:
    //    var str = $ctx.getString();      //获取当前Context对应的字符串
    //    alert($ctx.getString())          //alert当前Context对应的字符串
    //    var json = $ctx.getJSONObject(); //获取当前Context，返回值为json
    //    json["x"] = "a";        //为当前json增加字段
    //    json["y"] = [];           //为当前json增加数组
    //    $ctx.push(json);            //设置context，并自动调用数据绑定
    //    
    //    put方法需手动调用databind()
    //    var x = $ctx.get("x");    //获取x字段值
    //    $ctx.put("x", "b");     //设置x字段值
    //    $ctx.put("x", "b");     //设置x字段值
    //    $ctx.databind();            //调用数据绑定才能将修改的字段绑定到控件上
    //    var p1 = $param.getString("p1");   //获取参数p2的值，返回一个字符串
    //    var p2 = $param.getJSONObject("p2");   //获取参数p3的值，返回一个JSON对象
    //    var p3 = $param.getJSONArray("p3");   //获取参数p1的值，返回一个数组
    
    //your initialize code below...
    
}
    
function com$yonyou$ncmm_pac_pda$StockUpScanController$evaljs(js){
    eval(js)
}
function back(sender, args){
    $view.close();
}
function loadmenu(sender, args){
    StockUpUtil.openDropDownList("btn_menu");
}
function com$yonyou$ncmm_pac_pda$StockUpScanController$imagebutton0_onclick(sender, args){
    $scanner.open({
        bindfield: "vbarcode",
        callback: "onScantxtInput()"
    });
}
function onScantxtInput(sender, args){
    $ctx.dataCollect();
    var marbarcode = $ctx.getString("vbarcode");
    parseMarCode(marbarcode);
    $id("textbox0").set("value", null);
    if(NCMMPubUtil.isEmpty($ctx.getString("zcpk_rack_name"))){
    $id("textbox12").focus();
    }
    else{
    $id("textbox0").focus();
    }
}

    //自制货位调整单节点扫描物料码后展示物料存在存量的货位信息
    function getlocationinfo(marID,pk_stordoc) {
        var condition = {};
		condition['storcode_h'] = "=\'" + pk_stordoc + "\'";
		condition['cmaterialvid'] = "=\'" + marID + "\'";
       //查询存量
		$id("textarea0").set("value", "存量数据加载中...");
		//测试连接
		NCMMDBUtil.testNCConnection(function(data1) {
			if(data1 == false || data1 == "false") {
				$id("textarea0").set("value", "没有查询到当前物料的存量信息：查询失败请检查网络设置");
				return;
			} else {
				queryStockByStoreAndCode(condition, function(data) {
					if(data != null) {
						//绑定列表
						var arr = new Array();
						var count = 0;
						var count2 = 0;
						var billinfos = [];
						billinfos = data["billinfos"];
						if(NCMMPubUtil.isNotEmpty(billinfos) && billinfos.length > 0) {
							for(var val = 0; val < billinfos.length; val++) {							    
								//alert("billinfos[" + val + "]:" + JSON.stringify(billinfos[val]));
								var billinfo = billinfos[val].billinfo;
								var head = billinfo.head;
								var items = billinfo.items;
								//arr.push("物料：" + head.vinvcode + " [" + head.vinvname + "]\n");
								//arr.push("规格 ：" + (!head.vinvspec ? "" : head.vinvspec) + "型号：" + (!head.vinvtype ? "" : head.vinvtype) + "\n");
								if(!!head.cscode){
								arr.push("货位：" + head.cscode + " [" + head.csname + "]\n");
								}
								arr.push("批次号：" + (!head.vbatchcode?"":(head.vbatchcode + " [" + head.tbatchtime + "]"))+"\n");
								arr.push("主单位：" + head.cmeasname + "  单位：" + head.measname + "\n");
								arr.push("结存主数量：" + items[0].item.nquantity + "   结存数量：" + head.nonhandastnum + "\n");
								arr.push("----------------------------------------------\n");
								
							}				
							var showData=arr.join("");
							//showData = NCMMPubUtil.htmlspecialjsonarray2UI(showData);							
							//$alert(showData);
							//$ctx.put("result", arr.join(""));
							
			               $ctx.put("locationinfo",showData);
			               $ctx.dataBind();
						} else {							
							$ctx.put("locationinfo",{});
							$id("textarea0").set("value", "没有查询到当前物料的存量信息");;
							$ctx.dataBind();
						}
					} else {						
						$ctx.put("listdata",{});
							$ctx.dataBind();
						$id("textarea0").set("value", "没有查询到当前物料的存量信息");
					}

				});
			}
		});	
    }
    function queryStockByStoreAndCode(condition, callback) {
		//拼装HTTP请求参数
		var httpURL = NCMMHttpUtil.getQuestURL(NCMMHttpUtil.BILL);
		var aggvo = "aggvo";
		var httpparam = NCMMHttpUtil.getHTTPRequestParam("MAPP_ONHANDNUM_INV", aggvo, condition);
		//发送HTTP请求	
		NCMMHttpUtil.sendHTTPRequest(httpURL, httpparam, function(data, issuccess) {
			if(issuccess > 0) {
				if(issuccess == 1) { //成功
					if(callback != null && typeof(callback) == 'function') {
						//	$alert("data=" + $jsonToString(data));
						callback(data);
					}
				} else {
					//afterError("下载", "NC端没有返回单据记录"); //成功但记录为空
					if(callback != null && typeof(callback) == 'function') {
						callback(data);
						//callback(null);
					};
				}
			} else { //失败
				afterError("下载", data);
				if(callback != null && typeof(callback) == 'function') {
					callback(null);
				};
			}
		});
	};

    //解析物料码
    function parseMarCode(marbarcode) {
        var listJson = $ctx.getJSONObject();
        if(NCMMPubUtil.isEmpty(marbarcode)) {
            $alert("物料码为空！");
            return;
        }       
        var marJson = NCMMBarcodeParseUtil.parseMaterialBar(marbarcode);
        var marID = marJson.pk_material;
        if(NCMMPubUtil.isEmpty(marID)) {
            $alert("解析物料码失败，请检查输入是否正确，或更新物料档案！");
            return;
        }
        
        listJson["pk_material"] = marJson.pk_material;
        listJson["pk_material_code"] = marJson.code;
        var conditon = " where pk_material='" + marJson.pk_material + "'";
        var results = NCMMPubUtil.queryVONoCallback(MaterialVO, conditon);
        if(NCMMPubUtil.isEmpty(results) || results == "[]") {
            $alert("不存在当前物料，请更新物料档案！");
            return;
        }
        results = $stringToJSON(results);
            listJson["pk_material_name"] = results[0].name;
            listJson["materialspec"] = results[0].materialspec;
            listJson["materialtype"] = results[0].materialtype;            
            //主单位
            listJson["cunitid"] = results[0].pk_measdoc;
            listJson["cunitid_name"] = results[0].pk_measdoc_name;
            //辅单位,换算率从辅单位管理档案获取 默认库存单位        
            var unitWhere=" where pk_material='" + marJson.pk_material + "' and isstockmeasdoc='Y'";
            var unitresults=NCMMPubUtil.queryVONoCallback(MaterialConvertVO,unitWhere);
            unitresults = $stringToJSON(unitresults);
            //如果默认库存单位为空，取主单位
            if(NCMMPubUtil.isEmpty(unitresults) || unitresults == "[]") {
                //换算率
                listJson["vchangerate"] = "1/1";
                //辅单位取物料档案下默认库存单位
                listJson["castunitid"] = results[0].pk_measdoc;
                listJson["castunitid_name"] = results[0].pk_measdoc_name;
            }
            else{
                //换算率
                listJson["vchangerate"] = unitresults[0].vchangerate;
                //辅单位取物料档案下默认库存单位
                listJson["castunitid"] = unitresults[0].pk_measdoc;
                listJson["castunitid_name"] = unitresults[0].measdoc_name;
            }
        
        if(NCMMPubUtil.isNotEmpty(marJson.vbatchcode)) {
            listJson["vbatchcode"] = marJson.vbatchcode;
            listJson["pk_batchcode"] = marJson.pk_batch;
        }
        if(NCMMPubUtil.isNotEmpty(marJson.vserialcode)) {
            listJson["vserialcode"] = marJson.vserialcode;
        }
        var vchangerate = listJson["vchangerate"];
        var num = 1;	
		var nastnum = StockUpUtil.getAstnum(1, vchangerate);        
        if(NCMMPubUtil.isNotEmpty(marJson.nnum)){
		   num=marJson.nnum;
		   nastnum=StockUpUtil.getAstnum(num, vchangerate);
		}else if(NCMMPubUtil.isNotEmpty(marJson.nassistnum)){
		   nastnum=marJson.nassistnum;
		   num=StockUpUtil.getNum(nastnum,vchangerate);
		}
		var bitnum = StockUpUtil.getUnitBitnumber(listJson["cunitid"]);
		if(!NCMMPubUtil.isEmpty(bitnum)) {
				num = num.toFixed(bitnum);
		}
		var astbitnum = StockUpUtil.getUnitBitnumber(listJson["castunitid"]);
			if(!NCMMPubUtil.isEmpty(astbitnum)) {
				nastnum = nastnum.toFixed(astbitnum);
			}
        listJson["nassistnum"]=nastnum;
        listJson["nnum"] =num;
        //listJson["vchangerate"] = StockUpUtil.getvchangerate(listJson["nnum"], listJson["nassistnum"]);
        //组织默认取业务设置默认组织
		var stockorg = $cache.read("defaultstockorg") ? $cache.read("defaultstockorg") : "";
		if(stockorg != "") {
		    stockorg = $stringToJSON(stockorg);
		}
		else{
		   $alert("请设置默认库存组织！");
		   return;
		}
		listJson["pk_org"] = stockorg["pk_stockorg"];
		//仓库默认取业务设置默认仓库
		var stordoc = $cache.read("defaultstordoc") ? $cache.read("defaultstordoc") : "";
		if(stordoc != "") {
		    stordoc = $stringToJSON(stordoc);
		}
		else{
		    $alert("请设置默认仓库！");
		    return;
		}
		listJson["cwarehouseid"] = stordoc["pk_stordoc"];
		listJson["cwarehouseid_name"] = stordoc["name"];
		listJson["pk_scan"] = getStockUpScanPK();
		NCMMPubUtil.insertVO(StockUpVO, listJson);
		getlocationinfo(marID,stordoc["pk_stordoc"]);
		console.log($jsonToString(listJson));
		$ctx.push(listJson);
		$ctx.dataBind();
    }
    
    function getStockUpScanPK() {
        var date = new Date().getTime();
        var pk = "40081TM" + date.toString();
        return pk;
    }
    
function com$yonyou$ncmm_pac_pda$StockUpScanController$onload(sender, args){
    var row = $param.getJSONObject("row");
    NCMMPubUtil.createTable(StockUpVO);
    if(!(row == null || row == "")) {
        var json = {};
        json = row;
        json = NCMMPubUtil.htmlspecialjson2UI(json);
        $ctx.push(json);
        $ctx.dataBind();
    }    
    var stockUpRack= $cache.read("defaultStockUpRack") ? $cache.read("defaultStockUpRack") : "";
	if(NCMMPubUtil.isEmpty(stockUpRack)) {
		 $alert("请设置备货区！");
		 $view.close();
		    return;
	}
	stockUpRack  = $stringToJSON(stockUpRack);
	$ctx.put("zrpk_rack_name", stockUpRack["name"]);
	$ctx.put("zrpk_rack", stockUpRack["pk_rack"]);
	$ctx.dataBind();
    //组织默认取业务设置默认组织
		var stockorg = $cache.read("defaultstockorg") ? $cache.read("defaultstockorg") : "";
		if(NCMMPubUtil.isEmpty(stockorg )) {
		   $alert("请设置默认库存组织！");
		   return;
		}
		//仓库默认取业务设置默认仓库
		var stordoc = $cache.read("defaultstordoc") ? $cache.read("defaultstordoc") : "";
		if(NCMMPubUtil.isEmpty(stordoc)) {
		    $alert("请设置默认仓库！");
		    return;
		}
}

	function getRefParam(reftype, callback) {
	    var condition = {
			"ncbillcode": reftype
		};
		NCMMPubUtil.queryVOByConditions(AppmappingheadVO, condition, function(data) {
			var jsondata = {
				bdlistdata: eval(data)
			};
			//$alert(jsondata);
			var reftitle = (jsondata.bdlistdata)[0]["appbillname"];
			if((jsondata.bdlistdata)[0]["downloadnum"] == "" || (jsondata.bdlistdata)[0]["downloadnum"] == "0") {
				$alert("【" + reftitle + "】没有可参照的数据");
				if(callback != null && callback != undefined && typeof(callback) == 'function') {
					callback(null);
				}
				return;
			}
			var reftablename = (jsondata.bdlistdata)[0]["apptablename"]; //本地表名
			var jsonparam = {
				reftype: reftype, //外系统调用标识
				reftitle: reftitle, //元数据显示名称
				reftablename: reftablename //本地表名
			};
			if(callback != null && callback != undefined && typeof(callback) == 'function') {
				callback(jsonparam);
			}
		});
	}

	// 打开货位参照页面
	function openRackRefPage(ncbillcode, ctxnamekey, ctxpkkey, pkfiel, pk_stordoc) {
		var jsonparam = {};
		getRefParam(ncbillcode, function(data) {
			jsonparam = data;
		});

		if(jsonparam == null) {
			//$alert("jsonparam is null!");
			return;
		}

		jsonparam["wheresql"] = " where pk_stordoc='" + pk_stordoc + "'";
		console.log(jsonparam["wheresql"]);
		$view.open({
			viewid: "com.yonyou.ncmm_pac_pda.RefPage", //目标页面
			isKeep: "true", //打开新页面的同时是否保留当前页面，true为保留，false为不保留
			data: jsonparam,
			callback: function() {
				var refdata = $param.getJSONObject("data");
				$ctx.put(ctxnamekey, refdata["name"]);
				$ctx.put(ctxpkkey, refdata[pkfiel]);
				$ctx.dataBind();
				$cache.write("default" + ctxnamekey, $jsonToString(refdata));

				//设置了默认库存组织后，自动下载默认库存组织下的仓库
				//where pk_org='库存组织编码'
				if(ctxnamekey == "stockorg") {
					var condition = {
						"pk_org": "='" + refdata["code"] + "'"
					};
					processDocDataFromNC(StordocVO, condition);
				}
			}
		});
	}


function localSave(sender, args){
    var json = $ctx.getJSONObject();
    if(json.nnum == null || json.nnum == 0 || json.nnum == "0") {
        $alert("主数量不能为空或0！");
        return;
    }
    if(json.nassistnum == null || json.nassistnum == 0 || json.nassistnum == "0") {
        $alert("数量不能为空或0！");
        return;
    }
    if(!$.isNumeric(json.nnum) || !$.isNumeric(json.nassistnum)) {
        $alert("数量输入不合法！");
        return;
    }
    json = NCMMPubUtil.htmlspecialjson2UI(json);
    var isSuccess = doSave(json);
    if(isSuccess == true) {
        $toast("保存成功！");
    }
    $id("textbox0").focus();
}

function doSave(json) {
    //如果批次号修改过
    //if(NCMMPubUtil.isEmpty(json["vbatchcode"])) {
        json["pk_batchcode"] = "";
    //} else {
    /** 去掉批次档案
        if(NCMMPubUtil.isTableExist(BatchcodeVO)) {
            var sql = " where vbatchcode='" + json["vbatchcode"] + "' and cmaterialvid='" + json["pk_material"] + "'";
            var pk_batchcode = "";
            NCMMPubUtil.queryVO(BatchcodeVO, sql, function(data) {
                if(typeof(data) == 'undefined' || data == null || data.length == 0) {
                    return;
                } else {
                    var vos = eval(data);
                    if(vos != null && vos.length > 0) {
                        pk_batchcode = vos[0].pk_batchcode;
                    }
                }
            });
        }
        if(NCMMPubUtil.isEmpty(pk_batchcode)) {
            $alert("批次号不在批次档案中，请检查输入或更新批次档案！");
            return false;
        }
        json["pk_batchcode"] = pk_batchcode;
        */
    //}
    if(NCMMPubUtil.isEmpty(json["pk_scan"])) {
        json["pk_scan"] = getStockUpScanPK();
        NCMMPubUtil.insertVO(StockUpVO, json);
    } else {
        NCMMPubUtil.updateVO(StockUpVO, json);
    }
    $ctx.push(json);
    $ctx.dataBind();
    return true;
}

function onOneScanSubmit(sender, args){
    var json = $ctx.getJSONObject();
    if (NCMMPubUtil.isEmpty(json)) {
        $alert("无扫描数据，不能提交！");
        return;
    }
    if(!json.cwarehouseid || json.cwarehouseid == null || json.cwarehouseid == "") {
        $alert("默认库存仓库不能为空！");
        return;
    }
    if(!json.zcpk_rack || json.zcpk_rack == null || json.zcpk_rack == "") {
        $alert("转出货位不能为空！");
        return;
    }
    if(!json.zrpk_rack || json.zrpk_rack == null || json.zrpk_rack == "") {
        $alert("转入货位不能为空！");
        return;
    }
    if(json.nnum == null || json.nnum == 0 || json.nnum == "0") {
        $alert("主数量不能为空或0！");
        return;
    }
    if(json.nassistnum == null || json.nassistnum == 0 || json.nassistnum == "0") {
        $alert("数量不能为空或0！");
        return;
    }
    if(!$.isNumeric(json.nnum) || !$.isNumeric(json.nassistnum)) {
        $alert("数量输入不合法！");
        return;
    }
    $js.showLoadingBar();
	json = NCMMPubUtil.htmlspecialjson2UI(json);
	var isSuccess = doSave(json);
	if(isSuccess == false) {
	    $js.hideLoadingBar();
	    return;
	}
	var sql = " where pk_scan='" + json.pk_scan + "'";
	var vo = {};
	NCMMPubUtil.queryVO(StockUpVO, sql, function(scanData) {
	    if(typeof(scanData) == 'undefined' || scanData == null || scanData.length == 0) {
	        return;
	    }
	    var vos = eval(scanData);
	    vos = NCMMPubUtil.htmlspecialjsonarray2UI(vos);
	    vo = vos[0];
	});
	if(NCMMPubUtil.isEmpty(vo)) {
	    $js.hideLoadingBar();
	    $alert("当前扫描记录已经被删除，不能提交！")
	    return;
	}
	var head = {};
	head["pk_org"] = vo["pk_org"];
    head["cwarehouseid"] = vo["cwarehouseid"];
    var item = {};
    item["crowno"] = 10;
    item["pk_material"] = vo["pk_material"];
    item["nassistnum"] = vo["nassistnum"];
    item["nnum"] = vo["nnum"];
    item["castunitid"] = vo["castunitid"];
    item["cunitid"] = vo["cunitid"];
    item["vchangerate"] = vo["vchangerate"];
    item["zcpk_rack"] = vo["zcpk_rack"];
    item["zrpk_rack"] = vo["zrpk_rack"];
    //item["pk_batchcode"]=vo["pk_batchcode"];
    item["vbatchcode"]=vo["vbatchcode"];
    if(NCMMPubUtil.isNotEmpty(vo.vserialcode)){
      var bbitem={
         "vserialcode":vo.vserialcode,
         "nnum":vo.nnum,
         "nassistnum":vo.nassistnum
      };
      var bbitems = [{
				"bbitem": bbitem
			}];
	  item["bbitems"] = bbitems;
    }
    var billinfo = {};
    billinfo["head"] = head;
    var items = [{
	    "item": item
	}];
	billinfo["items"] = items;
	var billinfos = [{
	    "billinfo": billinfo
	}];
	var submitvos = [];
	submitvos.push(vo);
	//$alert(billinfos);
	//测试连接
	NCMMDBUtil.testNCConnection(function(data) {
	    if(data == false || data == "false") {
	        $js.hideLoadingBar();
	        $toast("连接服务器失败，无法提交！");
			return;
	    } else {
	        NCMMDBUtil.submitLocaldataToNC("4Qsave", billinfos, function(commitInfo) {
	            $js.hideLoadingBar();
	            if(!NCMMPubUtil.isEmpty(commitInfo)) {
	                if(commitInfo.return == null || commitInfo.return == "") {
	                    $js.hideLoadingBar();
	                    $alert("提交失败：" + $jsonToString(commitInfo));
	                } else if(commitInfo["return"].returnFlag == 1) {
	                    $toast("提交成功！");
	                    StockUpUtil.deleteaftersubmit(submitvos);
	                    var list = {
	                     zcpk_rack: vo["zcpk_rack"],
	                     zcpk_rack_name: vo["zcpk_rack_name"],
                         zrpk_rack:vo["zrpk_rack"],
                         zrpk_rack_name:vo["zrpk_rack_name"]
	                    };
	                    $ctx.push(list);
	                    $ctx.dataBind();
	                    $id("textbox0").focus();
	                } else {
	                    $alert("提交失败" + $jsonToString(commitInfo.return.returnDesc));
	                }
	            } else {
	                $alert("提交失败");
	            }
	        });
	    }
	});
}
function outRackEdit(sender, args){
    var zcpk_rack_code = $ctx.getString("zcpk_rack_name");
    if(NCMMPubUtil.isEmpty(zcpk_rack_code)) {
			$ctx.put("zcpk_rack", "");
			$ctx.put("zcpk_rack_name", "");
			$ctx.dataBind();
			return;
		}
    var wheresql = "where " + RackVO.CODE.name + " = '" + zcpk_rack_code + "' or " + RackVO.NAME.name + " = '" + zcpk_rack_code+"'";
    var stordoc = $cache.read("defaultstordoc");
		if(!NCMMPubUtil.isEmpty(stordoc)) {
			wheresql = wheresql + " and pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";
		}
    var retData = NCMMPubUtil.queryVONoCallback(RackVO, wheresql);
    if(retData == null || (eval(retData)).length == 0) {
	    $alert("没有货位【" + zcpk_rack_code + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
		return;
    }
    retData = eval(retData);
    $ctx.put("zcpk_rack", retData[0]["pk_rack"]);
	$ctx.put("zcpk_rack_name", retData[0]["name"]);
	$id("textbox13").focus();
}

function com$yonyou$ncmm_pac_pda$StockUpScanController$outRackRef(sender, args){
    var stordoc = $cache.read("defaultstordoc");
		if(stordoc == null || stordoc == "") {
			$alert("默认仓库不能为空，请设置！");
			return;
		}
		var wheresql = " where pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";
		NCMMPubUtil.openRefPage("PDARACK", "zcpk_rack_name", "zcpk_rack", "pk_rack", wheresql);

}
function com$yonyou$ncmm_pac_pda$StockUpScanController$outRackScan(sender, args){
     $scanner.open({
			bindfield: "rack",
			callback: "rackScanBack()"
		});
	}

	function rackScanBack() {
		var rack = $ctx.getString("rack");
		var wheresql = " where code='" + rack + "'";
		var stordoc = $cache.read("defaultstordoc");
		if(!NCMMPubUtil.isEmpty(stordoc)) {
			wheresql = wheresql + " and pk_stordoc='" + $stringToJSON(stordoc).pk_stordoc + "'";
		}
		getRackInfoByWhereSql(wheresql, rack,"zcpk_rack","zcpk_rack_name");
	}

	function getRackInfoByWhereSql(wheresql, rack,pkField,nameField) {
		if(NCMMPubUtil.isTableExist(RackVO) == false) {
			$alert("没有货位【" + rack + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
			$ctx.put(nameField, "");
			$ctx.put(pkField, "");
			$ctx.dataBind();
			return;
		}
		NCMMPubUtil.queryVO(RackVO, wheresql, function(data) {
			//2 打开扫描记录编辑界面
			if(NCMMPubUtil.isEmpty(data)) {
				$alert("没有扫描货位【" + rack + "】记录，请更新货位数据，或检查当前扫描货位是否属于默认仓库！");
				$ctx.put(nameField, "");
				$ctx.put(pkField, "");
				$ctx.dataBind();
				return;
			}
			var vos = eval(data);
			$ctx.put(nameField, vos[0].name);
			$ctx.put(pkField, vos[0].pk_rack);
			$ctx.dataBind();
		});

}


//辅计量单位参照
function com$yonyou$ncmm_pac_pda$StockUpScanController$astUnitRef(sender, args){
   var listJson = $ctx.getJSONObject();
   var mateiralID=listJson.pk_material;
   if(NCMMPubUtil.isEmpty(mateiralID)){
     $alert("请先扫描物料！");
     return;
   }
   NCMMPubUtil.openAstUnitRefPage("castunitid_name", "castunitid", "vchangerate", mateiralID,"nnum","nassistnum");
}
function com$yonyou$ncmm_pac_pda$StockUpScanController$calNum(sender, args){
     var nn = args["newvalue"];
		if(NCMMPubUtil.isEmpty(nn)) {
			$ctx.put("nnum", "");
			$ctx.dataBind();
			return;
		}
		if(nn == "-") {
			return;
		}
		$ctx.dataCollect();
		if(!$.isNumeric(nn)) {
			$ctx.put("nassistnum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}
		if(StockUpUtil.isBsBitnumber(nn, $ctx.getString("castunitid"))) {
			$ctx.put("nassistnum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}
		$ctx.dataCollect();
		var nastnum = $ctx.getString("nassistnum");
		if(NCMMPubUtil.isEmpty(nastnum)) {
			$ctx.put("nnum", "");
			$ctx.dataBind();
			return;
		}
		if(!$.isNumeric(nastnum)) {
			$alert("扫描数量输入不合法！");
			return;
		}
		var vchangerate = $ctx.getString("vchangerate");
		var nnum = "";
		if(!NCMMPubUtil.isEmpty(nastnum)) {
			nnum = StockUpUtil.getNum(nastnum, vchangerate);
			var bitnum = StockUpUtil.getUnitBitnumber($ctx.getString("cunitid"));
			if(!NCMMPubUtil.isEmpty(bitnum)) {
				nnum = nnum.toFixed(bitnum);
			}
			//$alert(nnum);
			if(nnum.toString() == "NaN") {
				$alert("数量输入不合法！");
				return;
			}
		}
		$ctx.put("nnum", nnum);
		$ctx.dataBind();
}
function com$yonyou$ncmm_pac_pda$StockUpScanController$calAstNum(sender, args){
        var nn = args["newvalue"];
		if(NCMMPubUtil.isEmpty(nn)) {
			$ctx.put("nassistnum", "");
			$ctx.dataBind();
			return;
		}
		if(nn == "-") {
			return;
		}
		if(!$.isNumeric(nn)) {
			$ctx.put("nnum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}

		if(StockUpUtil.isBsBitnumber(nn, $ctx.getString("cunitid"))) {
			$ctx.put("nnum", args["oldvalue"]);
			$ctx.dataBind();
			return;
		}
		$ctx.dataCollect();
		var nnum = $ctx.getString("nnum");
		if(NCMMPubUtil.isEmpty(nnum)) {
			$ctx.put("nassistnum", "");
			$ctx.dataBind();
			return;
		}
		if(!$.isNumeric(nnum)) {
			$alert("扫描主数量输入不合法！");
			return;
		}
		var vchangerate = $ctx.getString("vchangerate");
		var nastnum = "";
		if(!NCMMPubUtil.isEmpty(nnum)) {
			nastnum = StockUpUtil.getAstnum(nnum, vchangerate);
			var bitnum = StockUpUtil.getUnitBitnumber($ctx.getString("castunitid"));
			if(!NCMMPubUtil.isEmpty(bitnum)) {
				nastnum = nastnum.toFixed(bitnum);
			}
			//$alert(nastnum);
			if(nastnum.toString() == "NaN") {
				$alert("数量输入不合法！");
				return;
			}
		}
		$ctx.put("nassistnum", nastnum);
		$ctx.dataBind();
}
function com$yonyou$ncmm_pac_pda$StockUpScanController$restart(sender, args){
     
}
com.yonyou.ncmm_pac_pda.StockUpScanController.prototype = {
    restart : com$yonyou$ncmm_pac_pda$StockUpScanController$restart,
    calAstNum : com$yonyou$ncmm_pac_pda$StockUpScanController$calAstNum,
    calNum : com$yonyou$ncmm_pac_pda$StockUpScanController$calNum,
    astUnitRef : com$yonyou$ncmm_pac_pda$StockUpScanController$astUnitRef,
    outRackScan : com$yonyou$ncmm_pac_pda$StockUpScanController$outRackScan,
    outRackRef : com$yonyou$ncmm_pac_pda$StockUpScanController$outRackRef,
    onload : com$yonyou$ncmm_pac_pda$StockUpScanController$onload,
    imagebutton0_onclick : com$yonyou$ncmm_pac_pda$StockUpScanController$imagebutton0_onclick,
    initialize : com$yonyou$ncmm_pac_pda$StockUpScanController$initialize,
    evaljs : com$yonyou$ncmm_pac_pda$StockUpScanController$evaljs
};
com.yonyou.ncmm_pac_pda.StockUpScanController.registerClass('com.yonyou.ncmm_pac_pda.StockUpScanController',UMP.UI.Mvc.Controller);
}catch(e){$e(e);}
